<template>
  <view class="health-index-details">
    <view class="header">
      <text class="title">健康指数详情</text>
    </view>
    
    <view class="overview">
      <view class="score-section">
        <text class="score">{{ healthIndex.total }}</text>
        <text class="label">总分</text>
      </view>
      
      <view class="assessment">
        <text class="assessment-rating">{{ healthAssessment.rating }}</text>
        <text class="assessment-suggestion">{{ healthAssessment.suggestion }}</text>
      </view>
    </view>
    
    <view class="details">
      <!-- 饮水指标 -->
      <view class="detail-item">
        <view class="detail-header">
          <view class="detail-icon-container" style="background-color: rgba(76, 175, 80, 0.1);">
            <image src="/static/icons/water-drop.png" class="detail-icon"></image>
          </view>
          <view class="detail-info">
            <text class="detail-name">饮水指标</text>
            <text class="detail-weight">权重: 30%</text>
          </view>
          <text class="detail-score">{{ healthIndex.water.score }}分</text>
        </view>
        <view class="detail-progress">
          <progress :percent="healthIndex.water.percentage" stroke-width="4" activeColor="#4CAF50" />
          <text class="progress-text">{{ healthIndex.water.percentage }}%</text>
        </view>
        <view class="detail-stats">
          <text>今日饮水量: {{ healthIndex.water.amount }}ml</text>
          <text>目标饮水量: {{ healthIndex.water.goal }}ml</text>
        </view>
      </view>
      
      <!-- 情绪指标 -->
      <view class="detail-item">
        <view class="detail-header">
          <view class="detail-icon-container" style="background-color: rgba(255, 152, 0, 0.1);">
            <image src="/static/icons/mood.png" class="detail-icon"></image>
          </view>
          <view class="detail-info">
            <text class="detail-name">情绪指标</text>
            <text class="detail-weight">权重: 25%</text>
          </view>
          <text class="detail-score">{{ healthIndex.mood.score }}分</text>
        </view>
        <view class="detail-stats">
          <text>今日情绪: {{ getMoodText(healthIndex.mood.type) }}</text>
          <text v-if="!healthIndex.mood.hasRecord" class="detail-tip">未记录今日情绪</text>
        </view>
      </view>
      
      <!-- 睡眠指标 -->
      <view class="detail-item">
        <view class="detail-header">
          <view class="detail-icon-container" style="background-color: rgba(33, 150, 243, 0.1);">
            <image src="/static/icons/sleep.png" class="detail-icon"></image>
          </view>
          <view class="detail-info">
            <text class="detail-name">睡眠指标</text>
            <text class="detail-weight">权重: 25%</text>
          </view>
          <text class="detail-score">{{ healthIndex.sleep.score }}分</text>
        </view>
        <view class="detail-stats">
          <text>睡眠质量: {{ getSleepText(healthIndex.sleep.quality) }}</text>
          <text v-if="!healthIndex.sleep.hasRecord" class="detail-tip">未记录今日睡眠</text>
        </view>
      </view>
      
      <!-- 如厕指标 -->
      <view class="detail-item">
        <view class="detail-header">
          <view class="detail-icon-container" style="background-color: rgba(156, 39, 176, 0.1);">
            <image src="/static/icons/toilet.png" class="detail-icon"></image>
          </view>
          <view class="detail-info">
            <text class="detail-name">如厕指标</text>
            <text class="detail-weight">权重: 20%</text>
          </view>
          <text class="detail-score">{{ healthIndex.toilet.score }}分</text>
        </view>
        <view class="detail-stats">
          <text>今日如厕次数: {{ healthIndex.toilet.count }}次</text>
          <text v-if="healthIndex.toilet.count === 0" class="detail-tip">未记录今日如厕</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { getHealthIndexDetails, getHealthAssessment } from '../utils/healthIndex.js'

export default {
  name: 'HealthIndexDetails',
  data() {
    return {
      healthIndex: {
        total: 0,
        water: { score: 0, weightedScore: 0, percentage: 0, amount: 0, goal: 0 },
        mood: { score: 0, weightedScore: 0, hasRecord: false, type: null },
        sleep: { score: 0, weightedScore: 0, hasRecord: false, quality: null },
        toilet: { score: 0, weightedScore: 0, hasRecord: false, count: 0 }
      },
      healthAssessment: {
        rating: '未评估',
        suggestion: '请完成健康指标记录以获取评估'
      }
    }
  },
  mounted() {
    this.refresh()
  },
  methods: {
    // 刷新健康指数数据
    refresh() {
      this.healthIndex = getHealthIndexDetails()
      this.healthAssessment = getHealthAssessment(this.healthIndex.total)
    },
    
    // 获取情绪文本
    getMoodText(moodType) {
      if (!moodType) return '未记录'
      
      const moodMap = {
        'happy': '开心',
        'excited': '兴奋',
        'neutral': '一般',
        'tired': '疲惫',
        'sad': '低落'
      }
      
      return moodMap[moodType] || '未知'
    },
    
    // 获取睡眠文本
    getSleepText(sleepQuality) {
      if (!sleepQuality) return '未记录'
      
      const sleepMap = {
        'good': '很好',
        'normal': '一般',
        'bad': '很差'
      }
      
      return sleepMap[sleepQuality] || '未知'
    }
  }
}
</script>

<style>
.health-index-details {
  padding: 20px;
}

.header {
  text-align: center;
  margin-bottom: 20px;
}

.title {
  font-size: 20px;
  font-weight: bold;
  color: #333;
}

.overview {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 30px;
}

.score-section {
  text-align: center;
  margin-bottom: 15px;
}

.score {
  font-size: 48px;
  font-weight: bold;
  color: #f4c242;
}

.label {
  font-size: 14px;
  color: #666;
  display: block;
}

.assessment {
  text-align: center;
}

.assessment-rating {
  font-size: 20px;
  font-weight: bold;
  color: #f4c242;
  margin-bottom: 5px;
  display: block;
}

.assessment-suggestion {
  font-size: 14px;
  color: #666;
  line-height: 1.5;
}

.details {
  margin-top: 20px;
}

.detail-item {
  background-color: #f9f9f9;
  border-radius: 10px;
  padding: 15px;
  margin-bottom: 15px;
}

.detail-header {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.detail-icon-container {
  width: 40px;
  height: 40px;
  border-radius: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-right: 10px;
}

.detail-icon {
  width: 24px;
  height: 24px;
}

.detail-info {
  flex: 1;
}

.detail-name {
  font-size: 16px;
  font-weight: bold;
  color: #333;
  display: block;
}

.detail-weight {
  font-size: 12px;
  color: #666;
}

.detail-score {
  font-size: 18px;
  font-weight: bold;
  color: #f4c242;
}

.detail-progress {
  margin: 10px 0;
  position: relative;
}

.progress-text {
  position: absolute;
  right: 0;
  top: 0;
  font-size: 12px;
  color: #666;
}

.detail-stats {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 14px;
  color: #666;
}

.detail-tip {
  color: #999;
  font-style: italic;
}
</style>